<template>
	<view class="order-list">
		<view class="order-list-content">
			<view class="" v-for="(item,index) in list" :key="index" @click="toDetail(item)">
				<view class="item-header">
					<view class="flex-align-center" @click.stop="$common.setClipboardData(item.orderNo)">
						<view class="fw-b">订单编号：{{item.orderNo || '-'}}</view>
						<static-image src="/pagesA/static/img/order/icon-copy.png" width="28" height="28" margin-left="8"></static-image>
					</view>
					<view class="font-s-12 fw-b text-over" :class="item.orderStatus===25?'color-green':[24,26,27].includes(item.orderStatus)?'color-red':[20,21].includes(item.orderStatus)?'color-orange':'color-blue'">
						{{$common.selectDictLabel(statusOptions,item.orderStatus) || '-'}}
					</view>
				</view>
				<view class="item-info">
					<view class="dis-flex">
						<view class="info-label">申请金额</view>
						<view class="color-red line-height-40 fw-b">¥{{item.applyAmount || '-'}}</view>
					</view>
					<view class="flex-align-center">
						<view class="dis-flex flex-1">
							<view class="info-label">借款期限</view>
							<view class="line-height-40">{{$common.selectDictLabel(dayOptions,item.applyTotalDay) || '-'}}</view>
						</view>
						<view class="dis-flex flex-1">
							<view class="info-label">还款周期</view>
							<view class="line-height-40">{{$common.selectDictLabel(termOptions,item.applyTotalTerm) || '-'}}</view>
						</view>
					</view>
					<view class="flex-align-center">
						<view class="dis-flex flex-1">
							<view class="info-label">还款方式</view>
							<view class="line-height-40">{{$common.selectDictLabel(methodOptions,item.repayMethod) || '-'}}</view>
						</view>
						<view class="dis-flex flex-1">
							<view class="info-label">借款用途</view>
							<view class="line-height-40">{{$common.selectDictLabel(purposeOptions,item.loanPurpose) || '-'}}</view>
						</view>
					</view>
				</view>
				<view class="item-handle">
					<view @click.stop="toDetail(item)">查看详情</view>
					<view @click.stop="handleSign(item)" class="primary-btn" v-if="item.approveStatus==2 && item.signStatus!=2">立即签约</view>
					<view @click.stop="$common.navigator('/pagesA/bill/index?orderId='+item.id)" class="primary-btn" v-if="item.isFund">查看账单</view>
					<view @click.stop="$common.navigator('/pagesA/bill/index?orderId='+item.id)" class="warning-btn" v-if="item.isFund && !item.isFinishRepay">立即还款</view>
				</view>
			</view>
		</view>
		<u-loadmore :status="status" v-if="list.length || status!='nomore'"/>
		<empty text="暂无借还记录" height="80vh" v-else></empty>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				typeOptions:[],
				list: [],
				purposeOptions:[],
				methodOptions:[],
				termOptions:[],
				dayOptions:[],
				statusOptions:[],
				queryParams: {
					pageNum: 1,
					pageSize: 15
				},
				status: 'loading'
			}
		},
		onLoad(e) {
			this.queryParams.isFund = e.isFund || ''
			this.getDicts()
			this.getList()
		},
		onReachBottom() {
			if(this.status === 'loadmore'){
				this.status = 'loading'
				this.getList()
			}
		},
		methods: {
			getDicts(){
				this.$request({
					url: '/system/dict/data/type/loan_purpose',
					method: 'get'
				}).then(res => {
					this.purposeOptions = res.data;
				})
				this.$request({
					url: '/system/dict/data/type/repayment_method',
					method: 'get'
				}).then(res => {
					this.methodOptions = res.data;
				})
				this.$request({
					url: '/system/dict/data/type/repayment_term',
					method: 'get'
				}).then(res => {
					this.termOptions = res.data;
				})
				this.$request({
					url: '/system/dict/data/type/loan_days',
					method: 'get'
				}).then(res => {
					this.dayOptions = res.data;
				})
				this.$request({
					url: '/system/dict/data/type/order_status',
					method: 'get'
				}).then(res => {
					this.statusOptions = res.data;
				})
			},
			getList(){
				this.$request({
					url: '/orderInfo/selectMyOrderPage',
					method: 'get',
					data:this.queryParams
				}).then(res => {
					this.list = this.list.concat(res.data.records)
					if(res.data.records.length<this.queryParams.pageSize){
						this.status = 'nomore'
					}else{
						this.status = 'loadmore'
						this.queryParams.pageNum++
					}
				})
			},
			handleSign(row){
				uni.showLoading({
					mask:true
				})
				this.$request({
					url: '/orderInfo/creditAuthenticationContract',
					method: 'post',
					data:{id: row.id}
				}).then(res => {
					window.location.href = res.data.signUrl
				})
			},
			toDetail(row){
				uni.navigateTo({
					url: '/pagesA/order/detail?orderId='+row.id
				})
			}
		}
	}
</script>
<style>
	page{
		background-color: #F5F7FA;
	}
</style>
<style lang="scss" scoped>
	.order-list {
		padding: 24rpx;
		.order-list-content{
			>view{
				padding: 0 24rpx 32rpx;
				background: #FFFFFF;
				border-radius: 24rpx;
				margin-bottom: 24rpx;
				padding: 28rpx 24rpx;
				.item-header{
					display: flex;
					justify-content: space-between;
					align-items: center;
					border-bottom: 1rpx solid #f5f5f5;
					padding-bottom: 28rpx;
					.text-over{
						max-width: 120rpx;
					}
				}
				.item-info{
					margin-top: 32rpx;
					>view{
						margin-top: 24rpx;
						.info-label{
							flex-shrink: 0;
							height: 40rpx;
							line-height: 40rpx;
							background: #F5F9FF;
							border-radius: 20rpx;
							padding: 0 14rpx 0 16rpx;
							color: #566D8F;
							margin-right: 16rpx;
							letter-spacing: 2rpx;
						}
						&:first-child{
							margin-top: 0;
						}
					}
				}
				.item-handle{
					display: flex;
					align-items: center;
					justify-content: flex-end;
					margin-top: 32rpx;
					>view{
						width: 184rpx;
						height: 72rpx;
						background: #F5F7FA;
						border-radius: 38rpx;
						font-weight: bold;
						text-align: center;
						line-height: 72rpx;
						margin-left: 24rpx;
						&.primary-btn{
							background: #1F78FF;
							color: #FFFFFF;
						}
						&.warning-btn{
							background: linear-gradient( 90deg, #FF6933 0%, #FF9147 100%);
							color: #FFFFFF;
						}
					}
				}
			}
		}
	}
</style>